<?php 
namespace app\admin\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
 * 
 */
class Cardtype extends Model
{
    //软删除
    use SoftDelete;
    //关联程序表
    public function software()
    {
        return $this->belongsTo('Software','cardtypesoftware','id');
    }
    //添加模型
    public function add($data)
    {
        # code...
        $validate=new \app\common\validate\Cardtype();
        if(!$validate->scene('add')->check($data)){
                return $validate->getError();
        }
       
        $result=$this->allowField(true)->save($data);
        if($result){
            return 1;
        }else{
            return '程序类型添加失败';
        }
    }

    //编辑模型
    public function edit($data)
    {
        # code...
        $validate=new \app\common\validate\Cardtype();
        if(!$validate->scene('edit')->check($data)){
                return $validate->getError();
        }
        /**
         * 
         *    'id'=>input('post.id'),
          *      'cardtypename'=>input('post.cardtypename'),
          *      'cardtypesoftware'=>input('post.cardtypesoftware'),
          *      'cardtypetype'=>input('post.cardtypetype'),
           *     'cardtypetime'=>input('post.cardtypetime')
         */
        $cardtypeInfo=$this->find($data['id']);
        $cardtypeInfo->cardtypename=$data['cardtypename'];
        $cardtypeInfo->cardtypesoftware=$data['cardtypesoftware'];
        $cardtypeInfo->cardtypetype=$data['cardtypetype'];
        $cardtypeInfo->cardtypetime=$data['cardtypetime'];
        $result=$cardtypeInfo->save();
        if($result){
            return 1;
        }else{
            return '卡密类型修改失败';
        }
    }

    



}